//引用 express 框架，创建实例 并赋值给app
var express = require('express')
var app = express()
var bodyParser = require('body-parser')
app.use(bodyParser.json())

//配置静态文件目录
app.use(express.static('static'))


// 返回页面

var sendHtml = function(path, response) {
    var fs = require('fs')
    var options = {
        encoding: 'utf-8'
    }
    fs.readFile(path, options, function(err,data){
        response.send(data)
    })
}
app.get('/',function(request,response) {
    var path = 'index.html'
    sendHtml(path, response)
})
app.get('/first',function(request,response) {
    var path = 'first.html'
    sendHtml(path, response)
})
app.get('/second',function(request,response) {
    var path = 'second.html'
    sendHtml(path, response)
})
app.get('/second_1',function(request,response) {
    var path = 'second_1.html'
    sendHtml(path, response)
})
app.get('/second_2',function(request,response) {
    var path = 'second_2.html'
    sendHtml(path, response)
})
app.get('/second_3',function(request,response) {
    var path = 'second_3.html'
    sendHtml(path, response)
})
app.get('/second_4',function(request,response) {
    var path = 'second_4.html'
    sendHtml(path, response)
})
app.get('/third',function(request,response) {
    var path = 'third.html'
    sendHtml(path, response)
})
app.get('/fourth',function(request,response) {
    var path = 'fourth.html'
    sendHtml(path, response)
})


// 引入model模块
const statisticAll = require('./model/module')
const statistic2 = require('./model/module2')
const statistic2_a = require('./model/module2_a')
const statistic2_b = require('./model/module2_b')
const statistic2_c = require('./model/module2_c')
const statistic2_d = require('./model/module2_d')
const statistic3 = require('./model/module3')
const statistic4 = require('./model/module4')
// 和前端 ajax 交互数据
// first.html
app.get('/api/notion', function(request,response) {
    var contents = statisticAll.notionAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/person', function(request,response) {
    var contents = statisticAll.personAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/situation', function(request,response) {
    var contents = statisticAll.situationAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/qa', function(request,response) {
    var contents = statisticAll.qaAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/point', function(request,response) {
    var contents = statisticAll.pointAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/process', function(request,response) {
    var contents = statisticAll.processAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/dr', function(request,response) {
    var contents = statisticAll.drAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/da1', function(request,response) {
    var contents = statisticAll.da1All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/da2', function(request,response) {
    var contents = statisticAll.da2All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/da3', function(request,response) {
    var contents = statisticAll.da3All()
    var r = JSON.stringify(contents)
    response.send(r)
})

// second.html
app.get('/api/2/notion', function(request,response) {
    var contents = statistic2.notionAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2/process', function(request,response) {
    var contents = statistic2.processAll()
    var r = JSON.stringify(contents)
    response.send(r)
})

// second_1.html
app.get('/api/2_a/ns', function(request,response) {
    var contents = statistic2_a.nsAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_a/point', function(request,response) {
    var contents = statistic2_a.pointAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_a/img_process', function(request,response) {
    var contents = statistic2_a.imgprocessAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_a/img1', function(request,response) {
    var contents = statistic2_a.img1All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_a/img2', function(request,response) {
    var contents = statistic2_a.img2All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_a/img3', function(request,response) {
    var contents = statistic2_a.img3All()
    var r = JSON.stringify(contents)
    response.send(r)
})

// second_2.html
app.get('/api/2_b/ns', function(request,response) {
    var contents = statistic2_b.nsAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_b/point', function(request,response) {
    var contents = statistic2_b.pointAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_b/process', function(request,response) {
    var contents = statistic2_b.processAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_b/img1', function(request,response) {
    var contents = statistic2_b.img1All()
    var r = JSON.stringify(contents)
    response.send(r)
})

// second_3.html
app.get('/api/2_c/ns', function(request,response) {
    var contents = statistic2_c.nsAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_c/point', function(request,response) {
    var contents = statistic2_c.pointAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_c/process', function(request,response) {
    var contents = statistic2_c.processAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_c/img1', function(request,response) {
    var contents = statistic2_c.img1All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_c/img2', function(request,response) {
    var contents = statistic2_c.img2All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_c/img3', function(request,response) {
    var contents = statistic2_c.img3All()
    var r = JSON.stringify(contents)
    response.send(r)
})

// second_3.html
app.get('/api/2_d/ns', function(request,response) {
    var contents = statistic2_d.nsAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_d/point', function(request,response) {
    var contents = statistic2_d.pointAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_d/process', function(request,response) {
    var contents = statistic2_d.processAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_d/img1', function(request,response) {
    var contents = statistic2_d.img1All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_d/img2', function(request,response) {
    var contents = statistic2_d.img2All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/2_d/img3', function(request,response) {
    var contents = statistic2_d.img3All()
    var r = JSON.stringify(contents)
    response.send(r)
})

// third.html
app.get('/api/3/simple', function(request,response) {
    var contents = statistic3.simpleAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/3/background', function(request,response) {
    var contents = statistic3.backgroundAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/3/img1', function(request,response) {
    var contents = statistic3.img1All()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/3/img2', function(request,response) {
    var contents = statistic3.img2All()
    var r = JSON.stringify(contents)
    response.send(r)
})

// fourth
app.get('/api/4/new', function(request,response) {
    var contents = statistic4.newAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/4/display', function(request,response) {
    var contents = statistic4.displayAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/4/medicine', function(request,response) {
    var contents = statistic4.medicineAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/4/learn', function(request,response) {
    var contents = statistic4.learnAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/4/emotion', function(request,response) {
    var contents = statistic4.emotionAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/4/life', function(request,response) {
    var contents = statistic4.lifeAll()
    var r = JSON.stringify(contents)
    response.send(r)
})
app.get('/api/4/game', function(request,response) {
    var contents = statistic4.gameAll()
    var r = JSON.stringify(contents)
    response.send(r)
})


// listen 函数的第一个参数是我们要监听的端口
var server = app.listen(80,function() {
    var host = server.address().address
    var port = server.address().port
    console.log("应用实例，访问地址为 http://%s:%s", host, port)
})
